{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 第二步：调整树的参数：max_depth"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1. 导入工具包"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "\n",
    "import seaborn as sns\n",
    "from matplotlib import pyplot as plt\n",
    "\n",
    "from xgboost import XGBClassifier\n",
    "import xgboost as xgb\n",
    "\n",
    "from sklearn.model_selection import GridSearchCV\n",
    "from sklearn.model_selection import StratifiedKFold\n",
    "from sklearn.model_selection import train_test_split\n",
    "\n",
    "from sklearn.metrics import log_loss\n",
    "\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2.导入数据 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "dpath = \"./data/\"\n",
    "data = pd.read_csv(dpath + \"RentListingInquries_FE_train.csv\")\n",
    "# data_test = pd.read_csv(dpath + \"RentListingInquries_FE_test.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "data train:  (16779, 228)\n"
     ]
    }
   ],
   "source": [
    "# 取三分之一的数据作为训练集\n",
    "data_train, data_val = train_test_split(data, test_size = 0.66,random_state = 0)\n",
    "print(\"data train: \",data_train.shape)\n",
    "# print(\"data test: \",data_test.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>bathrooms</th>\n",
       "      <th>bedrooms</th>\n",
       "      <th>price</th>\n",
       "      <th>price_bathrooms</th>\n",
       "      <th>price_bedrooms</th>\n",
       "      <th>room_diff</th>\n",
       "      <th>room_num</th>\n",
       "      <th>Year</th>\n",
       "      <th>Month</th>\n",
       "      <th>Day</th>\n",
       "      <th>...</th>\n",
       "      <th>walk</th>\n",
       "      <th>walls</th>\n",
       "      <th>war</th>\n",
       "      <th>washer</th>\n",
       "      <th>water</th>\n",
       "      <th>wheelchair</th>\n",
       "      <th>wifi</th>\n",
       "      <th>windows</th>\n",
       "      <th>work</th>\n",
       "      <th>interest_level</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>16779.000000</td>\n",
       "      <td>16779.000000</td>\n",
       "      <td>1.677900e+04</td>\n",
       "      <td>1.677900e+04</td>\n",
       "      <td>1.677900e+04</td>\n",
       "      <td>16779.000000</td>\n",
       "      <td>16779.000000</td>\n",
       "      <td>16779.0</td>\n",
       "      <td>16779.000000</td>\n",
       "      <td>16779.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>16779.000000</td>\n",
       "      <td>16779.000000</td>\n",
       "      <td>16779.000000</td>\n",
       "      <td>16779.000000</td>\n",
       "      <td>16779.000000</td>\n",
       "      <td>16779.000000</td>\n",
       "      <td>16779.000000</td>\n",
       "      <td>16779.000000</td>\n",
       "      <td>16779.000000</td>\n",
       "      <td>16779.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>1.209071</td>\n",
       "      <td>1.537994</td>\n",
       "      <td>4.002467e+03</td>\n",
       "      <td>1.784611e+03</td>\n",
       "      <td>1.718569e+03</td>\n",
       "      <td>-0.328923</td>\n",
       "      <td>2.747065</td>\n",
       "      <td>2016.0</td>\n",
       "      <td>5.009476</td>\n",
       "      <td>15.247631</td>\n",
       "      <td>...</td>\n",
       "      <td>0.002920</td>\n",
       "      <td>0.000298</td>\n",
       "      <td>0.184397</td>\n",
       "      <td>0.008940</td>\n",
       "      <td>0.000536</td>\n",
       "      <td>0.027773</td>\n",
       "      <td>0.001788</td>\n",
       "      <td>0.000894</td>\n",
       "      <td>0.000954</td>\n",
       "      <td>1.616485</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>0.495244</td>\n",
       "      <td>1.115954</td>\n",
       "      <td>3.569312e+04</td>\n",
       "      <td>1.781989e+04</td>\n",
       "      <td>1.228794e+04</td>\n",
       "      <td>0.949059</td>\n",
       "      <td>1.442402</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.824854</td>\n",
       "      <td>8.341423</td>\n",
       "      <td>...</td>\n",
       "      <td>0.053963</td>\n",
       "      <td>0.017260</td>\n",
       "      <td>0.387819</td>\n",
       "      <td>0.099066</td>\n",
       "      <td>0.023154</td>\n",
       "      <td>0.164326</td>\n",
       "      <td>0.042248</td>\n",
       "      <td>0.029887</td>\n",
       "      <td>0.030866</td>\n",
       "      <td>0.625818</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>4.500000e+01</td>\n",
       "      <td>2.250000e+01</td>\n",
       "      <td>4.500000e+01</td>\n",
       "      <td>-4.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>2016.0</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>2.498000e+03</td>\n",
       "      <td>1.225000e+03</td>\n",
       "      <td>1.066667e+03</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>2016.0</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>8.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>3.150000e+03</td>\n",
       "      <td>1.500000e+03</td>\n",
       "      <td>1.397500e+03</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>2016.0</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>15.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>2.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>4.100000e+03</td>\n",
       "      <td>1.850000e+03</td>\n",
       "      <td>1.962500e+03</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>2016.0</td>\n",
       "      <td>6.000000</td>\n",
       "      <td>22.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>2.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>6.000000</td>\n",
       "      <td>8.000000</td>\n",
       "      <td>4.490000e+06</td>\n",
       "      <td>2.245000e+06</td>\n",
       "      <td>1.496667e+06</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>12.000000</td>\n",
       "      <td>2016.0</td>\n",
       "      <td>6.000000</td>\n",
       "      <td>31.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>2.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8 rows × 228 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          bathrooms      bedrooms         price  price_bathrooms  \\\n",
       "count  16779.000000  16779.000000  1.677900e+04     1.677900e+04   \n",
       "mean       1.209071      1.537994  4.002467e+03     1.784611e+03   \n",
       "std        0.495244      1.115954  3.569312e+04     1.781989e+04   \n",
       "min        0.000000      0.000000  4.500000e+01     2.250000e+01   \n",
       "25%        1.000000      1.000000  2.498000e+03     1.225000e+03   \n",
       "50%        1.000000      1.000000  3.150000e+03     1.500000e+03   \n",
       "75%        1.000000      2.000000  4.100000e+03     1.850000e+03   \n",
       "max        6.000000      8.000000  4.490000e+06     2.245000e+06   \n",
       "\n",
       "       price_bedrooms     room_diff      room_num     Year         Month  \\\n",
       "count    1.677900e+04  16779.000000  16779.000000  16779.0  16779.000000   \n",
       "mean     1.718569e+03     -0.328923      2.747065   2016.0      5.009476   \n",
       "std      1.228794e+04      0.949059      1.442402      0.0      0.824854   \n",
       "min      4.500000e+01     -4.000000      0.000000   2016.0      4.000000   \n",
       "25%      1.066667e+03     -1.000000      2.000000   2016.0      4.000000   \n",
       "50%      1.397500e+03      0.000000      2.000000   2016.0      5.000000   \n",
       "75%      1.962500e+03      0.000000      4.000000   2016.0      6.000000   \n",
       "max      1.496667e+06      2.000000     12.000000   2016.0      6.000000   \n",
       "\n",
       "                Day       ...                walk         walls           war  \\\n",
       "count  16779.000000       ...        16779.000000  16779.000000  16779.000000   \n",
       "mean      15.247631       ...            0.002920      0.000298      0.184397   \n",
       "std        8.341423       ...            0.053963      0.017260      0.387819   \n",
       "min        1.000000       ...            0.000000      0.000000      0.000000   \n",
       "25%        8.000000       ...            0.000000      0.000000      0.000000   \n",
       "50%       15.000000       ...            0.000000      0.000000      0.000000   \n",
       "75%       22.000000       ...            0.000000      0.000000      0.000000   \n",
       "max       31.000000       ...            1.000000      1.000000      1.000000   \n",
       "\n",
       "             washer         water    wheelchair          wifi       windows  \\\n",
       "count  16779.000000  16779.000000  16779.000000  16779.000000  16779.000000   \n",
       "mean       0.008940      0.000536      0.027773      0.001788      0.000894   \n",
       "std        0.099066      0.023154      0.164326      0.042248      0.029887   \n",
       "min        0.000000      0.000000      0.000000      0.000000      0.000000   \n",
       "25%        0.000000      0.000000      0.000000      0.000000      0.000000   \n",
       "50%        0.000000      0.000000      0.000000      0.000000      0.000000   \n",
       "75%        0.000000      0.000000      0.000000      0.000000      0.000000   \n",
       "max        2.000000      1.000000      1.000000      1.000000      1.000000   \n",
       "\n",
       "               work  interest_level  \n",
       "count  16779.000000    16779.000000  \n",
       "mean       0.000954        1.616485  \n",
       "std        0.030866        0.625818  \n",
       "min        0.000000        0.000000  \n",
       "25%        0.000000        1.000000  \n",
       "50%        0.000000        2.000000  \n",
       "75%        0.000000        2.000000  \n",
       "max        1.000000        2.000000  \n",
       "\n",
       "[8 rows x 228 columns]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_train.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0,0.5,'Interest level')"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZUAAAEKCAYAAADaa8itAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAF+hJREFUeJzt3Xu0XnV95/H3xyAoVgQkWk3iBDFakXG8RKDi8gIUwbHAstDCuCSjrJXqIEhnrErtEhdqF1QLirc2FRBcXKSoQ+oNM4g4WoUk3C8iESykoIQJFxUBg9/54/kdfQjn8iTZ5zw8yfu11lln79/+7b2/+xw4n+zb70lVIUlSF54w7AIkSZsPQ0WS1BlDRZLUGUNFktQZQ0WS1BlDRZLUGUNFktQZQ0WS1BlDRZLUma2GXcBM22mnnWr+/PnDLkOSRsrKlSvvrqrZU/WbtlBJcjrwRuCuqtqttX0U+FPgYeAnwFur6t627DjgSOAR4Jiquqi17w98ApgFfK6qTmztOwPnATsCVwBvqaqHp6pr/vz5rFixostDlaTNXpJ/H6TfdF7++jyw/3pty4DdqurFwI+B4wCS7AocBryorfOZJLOSzAI+DRwA7Aoc3voCnAScUlULgHvoBZIkaYimLVSq6rvA2vXavlVV69rsD4G5bfog4LyqeqiqbgVWAbu3r1VVdUs7CzkPOChJgL2BC9r6ZwIHT9exSJIGM8wb9W8DvtGm5wC39y1b3doman86cG9fQI21jyvJ4iQrkqxYs2ZNR+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J9ou0c2x5CuJreZctvbEBtGjGOUixJ6oxnKpKkzhgqkqTOGCqSpM4YKpKkzhgqkqTOGCqSpM4YKpKkzhgqkqTO/H/c1vc38uqscwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0xb9da13b70>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "sns.countplot(data_train.interest_level)\n",
    "plt.xlabel(\"Number of occurrences\")\n",
    "plt.ylabel(\"Interest level\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "样本分布不均，大部分是不感兴趣"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3. 使用GridSearchCV调整树的参数：max_depth - 粗调"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "kfold = StratifiedKFold(n_splits = 5, shuffle = True, random_state = 6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 分离 X 和 y\n",
    "y_train = data_train[\"interest_level\"]\n",
    "X_train = data_train.drop(\"interest_level\", axis = 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'max_depth': range(3, 10, 2)}"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "max_depth = range(3,10,2)\n",
    "param_test2_1 = dict(max_depth = max_depth)\n",
    "param_test2_1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 构建分类器\n",
    "xgb2_1 = XGBClassifier(\n",
    "        learning_rate = 0.1,\n",
    "        n_estimators = 116,  # 第一轮调整获取的最优值\n",
    "        max_depth = 5,\n",
    "        min_child_weight = 1,\n",
    "        gamma = 0,\n",
    "        subsample = 0.3,\n",
    "        colsample_bytree = 0.8,\n",
    "        colsample_bylevel = 0.7,\n",
    "        objective = \"multi:softprob\",\n",
    "        nthread = -1, # 多线程\n",
    "        seed = 6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 构建grid search cv\n",
    "grid_search_1 = GridSearchCV(xgb2_1, param_grid = param_test2_1, scoring = \"neg_log_loss\", n_jobs = -1, cv = kfold)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "GridSearchCV(cv=StratifiedKFold(n_splits=5, random_state=6, shuffle=True),\n",
       "       error_score='raise',\n",
       "       estimator=XGBClassifier(base_score=0.5, booster='gbtree', colsample_bylevel=0.7,\n",
       "       colsample_bytree=0.8, gamma=0, learning_rate=0.1, max_delta_step=0,\n",
       "       max_depth=5, min_child_weight=1, missing=None, n_estimators=116,\n",
       "       n_jobs=1, nthread=-1, objective='multi:softprob', random_state=0,\n",
       "       reg_alpha=0, reg_lambda=1, scale_pos_weight=1, seed=6, silent=True,\n",
       "       subsample=0.3),\n",
       "       fit_params=None, iid=True, n_jobs=-1,\n",
       "       param_grid={'max_depth': range(3, 10, 2)}, pre_dispatch='2*n_jobs',\n",
       "       refit=True, return_train_score='warn', scoring='neg_log_loss',\n",
       "       verbose=0)"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 调用fit\n",
    "grid_search_1.fit(X_train, y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "E:\\ProgramData\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:122: FutureWarning: You are accessing a training score ('mean_train_score'), which will not be available by default any more in 0.21. If you need training scores, please set return_train_score=True\n",
      "  warnings.warn(*warn_args, **warn_kwargs)\n",
      "E:\\ProgramData\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:122: FutureWarning: You are accessing a training score ('split0_train_score'), which will not be available by default any more in 0.21. If you need training scores, please set return_train_score=True\n",
      "  warnings.warn(*warn_args, **warn_kwargs)\n",
      "E:\\ProgramData\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:122: FutureWarning: You are accessing a training score ('split1_train_score'), which will not be available by default any more in 0.21. If you need training scores, please set return_train_score=True\n",
      "  warnings.warn(*warn_args, **warn_kwargs)\n",
      "E:\\ProgramData\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:122: FutureWarning: You are accessing a training score ('split2_train_score'), which will not be available by default any more in 0.21. If you need training scores, please set return_train_score=True\n",
      "  warnings.warn(*warn_args, **warn_kwargs)\n",
      "E:\\ProgramData\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:122: FutureWarning: You are accessing a training score ('split3_train_score'), which will not be available by default any more in 0.21. If you need training scores, please set return_train_score=True\n",
      "  warnings.warn(*warn_args, **warn_kwargs)\n",
      "E:\\ProgramData\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:122: FutureWarning: You are accessing a training score ('split4_train_score'), which will not be available by default any more in 0.21. If you need training scores, please set return_train_score=True\n",
      "  warnings.warn(*warn_args, **warn_kwargs)\n",
      "E:\\ProgramData\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:122: FutureWarning: You are accessing a training score ('std_train_score'), which will not be available by default any more in 0.21. If you need training scores, please set return_train_score=True\n",
      "  warnings.warn(*warn_args, **warn_kwargs)\n"
     ]
    }
   ],
   "source": [
    "pd.DataFrame(grid_search_1.cv_results_).to_csv('my_preds_maxdepth_1.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Best params: {'max_depth': 5}\n",
      "Best score: -0.6144513491728422\n",
      "CV results: {'mean_fit_time': array([48.42677937, 68.8573925 , 86.40130625, 97.40324883]), 'std_fit_time': array([2.09833659, 2.83361914, 1.30088101, 7.36356508]), 'mean_score_time': array([0.17552567, 0.22515974, 0.27132907, 0.27679777]), 'std_score_time': array([0.03369711, 0.03010812, 0.03249603, 0.06516009]), 'param_max_depth': masked_array(data=[3, 5, 7, 9],\n",
      "             mask=[False, False, False, False],\n",
      "       fill_value='?',\n",
      "            dtype=object), 'params': [{'max_depth': 3}, {'max_depth': 5}, {'max_depth': 7}, {'max_depth': 9}], 'split0_test_score': array([-0.61114134, -0.59538967, -0.59870138, -0.61562526]), 'split1_test_score': array([-0.62758548, -0.6169598 , -0.61739594, -0.63345337]), 'split2_test_score': array([-0.63067615, -0.6197545 , -0.62669288, -0.62659252]), 'split3_test_score': array([-0.63835363, -0.62802467, -0.63200737, -0.65056588]), 'split4_test_score': array([-0.62520337, -0.61214441, -0.61431868, -0.6301633 ]), 'mean_test_score': array([-0.62658929, -0.61445135, -0.61781981, -0.6312774 ]), 'std_test_score': array([0.00890812, 0.01083981, 0.01147292, 0.01135804]), 'rank_test_score': array([3, 1, 2, 4]), 'split0_train_score': array([-0.59448794, -0.511209  , -0.3987138 , -0.28731828]), 'split1_train_score': array([-0.59069017, -0.50555897, -0.39483136, -0.28600644]), 'split2_train_score': array([-0.59064653, -0.50472264, -0.39149429, -0.28676134]), 'split3_train_score': array([-0.58890518, -0.50484588, -0.39245279, -0.28161188]), 'split4_train_score': array([-0.59188419, -0.50753609, -0.39379176, -0.283793  ]), 'mean_train_score': array([-0.5913228 , -0.50677452, -0.3942568 , -0.28509819]), 'std_train_score': array([0.00184584, 0.00243524, 0.00250189, 0.00211555])}\n"
     ]
    }
   ],
   "source": [
    "# print(\"Grid scores:\", grid_search_1.grid_scores)\n",
    "print(\"Best params:\", grid_search_1.best_params_)\n",
    "print(\"Best score:\", grid_search_1.best_score_)\n",
    "print(\"CV results:\", grid_search_1.cv_results_)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "粗调获得的最佳取值是5，在5周围进行细调"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4. 使用GridSearchCV调整树的参数：max_depth - 细调"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "max_depth = [4,5,6]\n",
    "param_test2_2 = dict(max_depth = max_depth)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 构建分类器\n",
    "xgb2_2 = XGBClassifier(\n",
    "        learning_rate = 0.1,\n",
    "        n_estimators = 116,  # 第一轮调整获取的最优值\n",
    "        max_depth = 5,\n",
    "        min_child_weight = 1,\n",
    "        gamma = 0,\n",
    "        subsample = 0.3,\n",
    "        colsample_bytree = 0.8,\n",
    "        colsample_bylevel = 0.7,\n",
    "        objective = \"multi:softprob\",\n",
    "        nthread = -1, # 多线程\n",
    "        seed = 6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 构建grid search cv\n",
    "grid_search_2 = GridSearchCV(xgb2_2, param_grid = param_test2_2, scoring = \"neg_log_loss\", n_jobs = -1, cv = kfold)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "GridSearchCV(cv=StratifiedKFold(n_splits=5, random_state=6, shuffle=True),\n",
       "       error_score='raise',\n",
       "       estimator=XGBClassifier(base_score=0.5, booster='gbtree', colsample_bylevel=0.7,\n",
       "       colsample_bytree=0.8, gamma=0, learning_rate=0.1, max_delta_step=0,\n",
       "       max_depth=5, min_child_weight=1, missing=None, n_estimators=116,\n",
       "       n_jobs=1, nthread=-1, objective='multi:softprob', random_state=0,\n",
       "       reg_alpha=0, reg_lambda=1, scale_pos_weight=1, seed=6, silent=True,\n",
       "       subsample=0.3),\n",
       "       fit_params=None, iid=True, n_jobs=-1,\n",
       "       param_grid={'max_depth': [4, 5, 6]}, pre_dispatch='2*n_jobs',\n",
       "       refit=True, return_train_score='warn', scoring='neg_log_loss',\n",
       "       verbose=0)"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 调用fit\n",
    "grid_search_2.fit(X_train, y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "E:\\ProgramData\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:122: FutureWarning: You are accessing a training score ('mean_train_score'), which will not be available by default any more in 0.21. If you need training scores, please set return_train_score=True\n",
      "  warnings.warn(*warn_args, **warn_kwargs)\n",
      "E:\\ProgramData\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:122: FutureWarning: You are accessing a training score ('split0_train_score'), which will not be available by default any more in 0.21. If you need training scores, please set return_train_score=True\n",
      "  warnings.warn(*warn_args, **warn_kwargs)\n",
      "E:\\ProgramData\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:122: FutureWarning: You are accessing a training score ('split1_train_score'), which will not be available by default any more in 0.21. If you need training scores, please set return_train_score=True\n",
      "  warnings.warn(*warn_args, **warn_kwargs)\n",
      "E:\\ProgramData\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:122: FutureWarning: You are accessing a training score ('split2_train_score'), which will not be available by default any more in 0.21. If you need training scores, please set return_train_score=True\n",
      "  warnings.warn(*warn_args, **warn_kwargs)\n",
      "E:\\ProgramData\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:122: FutureWarning: You are accessing a training score ('split3_train_score'), which will not be available by default any more in 0.21. If you need training scores, please set return_train_score=True\n",
      "  warnings.warn(*warn_args, **warn_kwargs)\n",
      "E:\\ProgramData\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:122: FutureWarning: You are accessing a training score ('split4_train_score'), which will not be available by default any more in 0.21. If you need training scores, please set return_train_score=True\n",
      "  warnings.warn(*warn_args, **warn_kwargs)\n",
      "E:\\ProgramData\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:122: FutureWarning: You are accessing a training score ('std_train_score'), which will not be available by default any more in 0.21. If you need training scores, please set return_train_score=True\n",
      "  warnings.warn(*warn_args, **warn_kwargs)\n"
     ]
    }
   ],
   "source": [
    "pd.DataFrame(grid_search_2.cv_results_).to_csv('my_preds_maxdepth_2.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Best params: {'max_depth': 5}\n",
      "Best score: -0.6144513491728422\n",
      "CV results: {'mean_fit_time': array([51.184231  , 65.9524024 , 66.40916243]), 'std_fit_time': array([3.01522688, 0.32857845, 7.03561123]), 'mean_score_time': array([0.17612562, 0.21975603, 0.19653888]), 'std_score_time': array([0.01579746, 0.01715391, 0.05597735]), 'param_max_depth': masked_array(data=[4, 5, 6],\n",
      "             mask=[False, False, False],\n",
      "       fill_value='?',\n",
      "            dtype=object), 'params': [{'max_depth': 4}, {'max_depth': 5}, {'max_depth': 6}], 'split0_test_score': array([-0.60212516, -0.59538967, -0.60284835]), 'split1_test_score': array([-0.61965636, -0.6169598 , -0.6174053 ]), 'split2_test_score': array([-0.61979488, -0.6197545 , -0.62163376]), 'split3_test_score': array([-0.62914119, -0.62802467, -0.62660226]), 'split4_test_score': array([-0.61723302, -0.61214441, -0.61299811]), 'mean_test_score': array([-0.61758748, -0.61445135, -0.61629522]), 'std_test_score': array([0.00874041, 0.01083981, 0.00809618]), 'rank_test_score': array([3, 1, 2]), 'split0_train_score': array([-0.55885105, -0.511209  , -0.45751712]), 'split1_train_score': array([-0.55321062, -0.50555897, -0.45288182]), 'split2_train_score': array([-0.55060238, -0.50472264, -0.45072119]), 'split3_train_score': array([-0.54992658, -0.50484588, -0.45555372]), 'split4_train_score': array([-0.55311508, -0.50753609, -0.4518169 ]), 'mean_train_score': array([-0.55314114, -0.50677452, -0.45369815]), 'std_train_score': array([0.00314284, 0.00243524, 0.00249381])}\n"
     ]
    }
   ],
   "source": [
    "# print(\"Grid scores:\", grid_search_2.grid_scores)\n",
    "print(\"Best params:\", grid_search_2.best_params_)\n",
    "print(\"Best score:\", grid_search_2.best_score_)\n",
    "print(\"CV results:\", grid_search_2.cv_results_)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "细调获得的最佳取值没有变化，也是5"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
